<template>
  <div class="flowCloumn h100">
    <div class="h100">
      <list-table-new v-bind="tableSetting" ref="klTable"></list-table-new>
    </div>
  </div>
</template>
<script>
import { getUpComingList } from "@/api/orderManagement/upComingCenter.js";
import { getSetCodes } from "@/api/businessConfigurationManagement/processConfiguration.js";
export default {
  data() {
    return {
      codeName: {},
      tableSetting: {
        selectionShow: false,
        pageConfig: {
          pageCode: "complete",
          userId: this.$store.getters.userInfo.namePy,
        },
        searchObj: {
          searchMethod: (params, sortStr) => {
            if (params.timeRange) {
              params.startDate = params.timeRange[0];
              params.endDate = params.timeRange[1];
            }
            params.baseParam = {
              setCode: params.moduleCode ? params.moduleCode.join(",") : null,
            };
            this.getTableData(params, sortStr);
          },
          queryData: {
            page: 1,
            pageCount: 15,
            type: 3,
          },
          searchArr: [
            {
              type: "select",
              label: "业务模块",
              model: "moduleCode",
              multiple: true,
              option: [],
            },
            {
              type: "datetimerange",
              label: "接收时间",
              model: "timeRange",
            },
            {
              type: "input",
              label: "标题",
              model: "title",
            },
          ],
        },
        //过滤器的值
        filterFormData: {},
        //过滤器的默认值
        defaultFilterData: {},
        userCustomData: [],
        actionList: [],
        column: [
          {
            width: "800",
            label: "标题",
            prop: "todoTitle",
            sortable: "custom",
          },
          {
            label: "业务模块",
            prop: "moduleName",
            sortable: "custom",
            formatter: (row) => {
              return this.codeName[row.moduleCode];
            },
          },
          {
            label: "发起人",
            prop: "startUser",
            sortable: "custom",
          },
          {
            label: "接收时间",
            prop: "preOperationTime",
            sortable: "custom",
          },
        ],
        paginationObj: {
          pageSizes: [15, 30, 50, 100],
        },
        totalNumber: 0,
        //表格方法
        tableMethods: {
          //点击行的方法
          rowClick: (row) => {
            this.goDetailPage(row);
          },
        },
      },
    };
  },
  created() {
    this.getAppCode();
  },
  mounted() {
    this.$refs.klTable.getTableConfig();
    this.updateData();
  },
  methods: {
    updateData() {
      this.$refs.klTable.searchData();
    },
    //获取应用编号
    async getAppCode() {
      let info = this.$store.getters.currentAppInfo.appCode;
      this.basicFormData = { appCode: info };
      let { data } = await getSetCodes(info);
      let setCodeNameList = [];
      data.forEach((item) => {
        let nameObj = {
          label: item.moduleCode || "",
          value: item.setCode || "",
        };
        setCodeNameList.push(nameObj);
        this.codeName[item.setCode] = item.moduleCode;
      });
      this.tableSetting.searchObj.searchArr[0].option = setCodeNameList;
    },
    // 获取表格数据
    getTableData(params, sortStr) {
      let queryData = Object.assign({}, params);
      if (sortStr.length > 0) {
        queryData.orders = sortStr;
      }
      getUpComingList(queryData).then((res) => {
        this.$set(this.tableSetting, "tableData", res.data.list);
        this.$set(this.tableSetting, "totalNumber", res.data.total);
      });
    },
    //跳转到详情页
    goDetailPage(row) {
      let router = null;
      let vehicleState = "";
      let vehicleStatus = "";
      if (row.moduleCode == "car") {
        switch (row.processCode) {
          case "part_time_driver_apply": //兼职司机申请
            router = "partTimeCertificationDetails";
            vehicleState = "wait_approve";
            vehicleStatus = "待审批";
            break;
          case "car_apply": //用车申请
            router = "applyVehicleDetails";
            vehicleState = "WAIT_REVIEW";
            vehicleStatus = "待审核";
            break;
          case "car_maintain": //车辆维修保养
            let title = row.title || row.todoTitle;
            if (title.indexOf("维修") != -1) {
              router = "vehicleRepairDetails"; //车辆维修
              vehicleState = "WAIT_REVIEW";
              vehicleStatus = "待审核";
            }
            if (title.indexOf("保养") != -1) {
              router = "vehicleProtectDetails"; //车辆保养
              vehicleState = "WAIT_REVIEW";
              vehicleStatus = "待审核";
            }
            break;
          case "car_delimit_apply": //车辆定编申请
            router = "vehicleEstablishmentDetails";
            vehicleState = "WAIT_REVIEW";
            vehicleStatus = "待审核";
            break;
          case "car_delimit_replace": //车辆更购
            router = "vehicleReplaceDetails";
            vehicleState = "wait_approve";
            vehicleStatus = "待审核";
            break;
          default:
            break;
        }
        const { href } = this.$router.resolve({
          name: router,
          query: {
            id: row.dataId,
            pageType: "edit",
            //vehicleState:vehicleState,
            //vehicleStatus :vehicleStatus
          },
        });
        window.open(href, "_blank");
      } else {
        router = this.$store.getters.fineDirtDataName(
          "module_code",
          row.processCode
        );
        //let path = router.split("?")[0];
        const { href } = this.$router.resolve({
          name: router,
          query: {
            id: row ? row.dataId : "",
            val: row ? row.dataId : "",
            pageType: "edit",
          },
        });
        window.open(href, "_blank");
      }
    },
    /* goDetailPage(row) {
      let router = this.$store.getters.fineDirtDataName(
        "module_code",
        row.processCode
      );
      //let path = router.split("?")[0];
      const { href } = this.$router.resolve({
        name: router,
        query: {
          id: row ? row.dataId : "",
          val: row ? row.dataId : "",
          pageType: "edit",
        },
      });
      window.open(href, "_blank");
    }, */
  },
};
</script>
<style lang="less" scoped>
.flowCloumn {
  display: flex;
  flex-flow: column nowrap;
}
</style>
